
const login = ()=>{
    return fetch('https://www.fastmock.site/mock/9e4bbf9e35ad15942010865690c87ac6/api/login',{method:'post'})
            .then(res=>res.json())
            .then(res=>res)
}
const getList = ()=>{
    return fetch('https://www.fastmock.site/mock/9e4bbf9e35ad15942010865690c87ac6/api/getgoodslist')
            .then(res=>res.json())
            .then(res=>res)
}

const IndexModel = {
  namespace: 'index',
  state: {
    name: '1234',
    goodslist:[]
  },
  effects: {
    *query({ payload }, { call, put }) {
    },
    *login(action,{call,put}){
        const username = yield call(login);
        yield put({type:'save',username:username.data.name})
    },
    *getList(action,{call,put}){
        const goodsList = yield call(getList);
        console.log(goodsList)
        yield put({type:'getGoodsList',goodslist:goodsList.data})
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        name:action.username
      };
    },
    getGoodsList(state, action) {
      return {
        ...state,
        goodslist:action.goodslist
      };
    },

  
  },
  subscriptions: {
    setup({ dispatch, history }) {
      return history.listen(({ pathname }) => {
        // if (pathname === '/') {
        //   dispatch({
        //     type: 'query',
        //   })
        // }
      });
    }
  }
};
export default IndexModel;
// https://www.fastmock.site/mock/9e4bbf9e35ad15942010865690c87ac6/api/login